package com.itheima.health.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @Author: lenovo
 * @Date: 14:43 2021/5/9
*/
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private CustomerUserDetail customerUserDetail;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(customerUserDetail);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();//跨站
        http.formLogin()
                .loginPage("http://localhost:8080/pages/login.html")
                .loginProcessingUrl("/user/login")
                .successForwardUrl("/user/loginsuccess")
                .failureForwardUrl("/user/loginfailure");
        http.logout()
                .logoutUrl("/user/logout")
                .logoutSuccessUrl("http://localhost:8080/pages/login.html");
    }
}
